import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../../../base.entity';
import BaseMachineMaintainProject from './base-machine-maintain-project.entity';

@Entity({ name: 'base_machine_maintain_project_list' })
export default class BaseMachineMaintainProjectList extends BaseEntity {
  @Column({
    type: 'varchar',
    length: 50,
    name: 'machine_code',
    comment: '设备编号',
  })
  @ApiProperty()
  machineCode: string;

  @Column({
    type: 'varchar',
    length: 50,
    name: 'maintain_project_code',
    comment: '保养项目编码',
  })
  @ApiProperty()
  maintainProjectCode: string;

  @Column({ type: 'varchar', length: 100, name: 'maintain_project_name', comment: '保养项目名称' })
  @ApiProperty()
  maintainProjectName: string;

  @Column({
    type: 'varchar',
    length: 50,
    name: 'unit',
    comment: '单元',
  })
  @ApiProperty()
  unit: string;

  @Column({
    type: 'varchar',
    length: 50,
    name: 'part',
    comment: '部位',
  })
  @ApiProperty()
  part: string;

  @Column({
    type: 'varchar',
    length: 50,
    name: 'period_rate_code',
    comment: '保养类型编码',
  })
  @ApiProperty()
  periodRateCode: string;

  @Column({
    type: 'varchar',
    length: 50,
    name: 'period_rate_name',
    comment: '保养类型名称',
  })
  @ApiProperty()
  periodRateName: string;

  @Column({ type: 'float', nullable: true, name: 'period_rate', comment: '保养周期' })
  @ApiProperty()
  periodRate: number;

  @Column({ type: 'varchar', nullable: true, comment: '备注' })
  @ApiProperty()
  remark: string;

  @Column({ type: 'varchar', nullable: true, name: 'file_name', comment: '附件名称' })
  @ApiProperty()
  fileName: string;

  @Column({ type: 'varchar', nullable: true, name: 'file_url', comment: '附件地址' })
  @ApiProperty()
  fileUrl: string;

  @ManyToOne(() => BaseMachineMaintainProject, (machineMaintainProject) => machineMaintainProject.machineMaintainProjectList)
  @JoinColumn({ name: 'machine_code', referencedColumnName: 'machineCode' }) // 确保外键配置正确
  machineMaintainProject: BaseMachineMaintainProject;
}
